﻿namespace Guru.Framework.Util
{
    using System;
    using System.Collections;
    using System.Text;

    public class PropertyUtil
    {
        private Hashtable _hash;

        public PropertyUtil()
        {
            _hash = new Hashtable();
        }

        public void Add(object key, object value)
        {
            try
            {
                _hash.Add(key, value);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void Remove(object key)
        {
            try
            {
                _hash.Remove(key);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public object GetValue(object key)
        {
            try
            {
                if (_hash.Contains(key) == true)
                {
                    return _hash[key];
                }
                else
                    return null;
            }
            catch (Exception)
            {
                throw;
            }
        }

        public string PropertyString
        {
            get
            {
                try
                {
                    IDictionaryEnumerator dictEnumerator = _hash.GetEnumerator();
                    StringBuilder strBuilder = new StringBuilder();
                    while (dictEnumerator.MoveNext())
                    {
                        strBuilder.AppendFormat("{0}={1}; ", dictEnumerator.Key, dictEnumerator.Value);
                    }
                    string retstr = strBuilder.ToString();
                    retstr = retstr.Substring(0, retstr.Length - 1);
                    return retstr;
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }


        public override string ToString()
        {
            return PropertyString;
        }
    }
}
